#pragma once
#include "Comm.h"

namespace COMM
{	

	class COMM_API ThreadSignal
	{
		MYLIB_NONCOPIED_CLASS(ThreadSignal);
	public:
		ThreadSignal(bool bInitialState=false);
		~ThreadSignal(void);
	
		// For a manual-reset event object:
		// set and keep the state to signaled until it is set explicitly to the non-signaled state .
		// all waiting threads that can be released immediately are released.
		void SetSignal();
		// set the state to non-signaled. 
		void ResetSignal();
		bool IsSignaled();
		bool WaitSignal(unsigned int timeoutMs = -1);
		
	private:
#ifdef COMM_MSVC
		HANDLE m_hSignal;
#else
		bool m_bSignalState;
		pthread_mutex_t m_mutex;
		pthread_cond_t	m_cond;
#endif
	};
}
